package logic

import (
	"context"

	"goods/goods"
	"goods/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetGoodsSkuByGoodsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetGoodsSkuByGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGoodsSkuByGoodsLogic {
	return &GetGoodsSkuByGoodsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetGoodsSkuByGoodsLogic) GetGoodsSkuByGoods(in *goods.GetGoodsSkuByGoodsRequest) (*goods.GetGoodsSkuByGoodsResponse, error) {
	// todo: add your logic here and delete this line
	res, err := l.svcCtx.GoodsSku.FindGoodsSku(context.Background(), in.SearchMsg, in.Page, in.PageSize)
	if err != nil {
		return &goods.GetGoodsSkuByGoodsResponse{Code: -1, Msg: "获取商品规格列表失败"}, err
	}
	datas := []*goods.Goods_Sku{}
	for i := 0; i < len(res); i++ {
		data := &goods.Goods_Sku{
			DishId: res[i].DishId,
			Name:   res[i].Name.String,
			Value:  res[i].Value.String,
		}
		datas = append(datas, data)
	}
	return &goods.GetGoodsSkuByGoodsResponse{Code: 200, Msg: "获取商品规格列表成功", Data: datas}, nil
}
